package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.TPayChannel;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ProxyAreaCode;
import com.ruoyi.business.service.IProxyAreaCodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * IP代理地域Controller
 * 
 * @author ruoyi
 * @date 2024-11-07
 */
@Controller
@RequestMapping("/business/ProxyAreaCode")
public class ProxyAreaCodeController extends BaseController
{
    private String prefix = "business/ProxyAreaCode";

    @Autowired
    private IProxyAreaCodeService proxyAreaCodeService;

    @RequiresPermissions("business:ProxyAreaCode:view")
    @GetMapping()
    public String ProxyAreaCode()
    {
        return prefix + "/ProxyAreaCode";
    }

    /**
     * 查询IP代理地域列表
     */
    @RequiresPermissions("business:ProxyAreaCode:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProxyAreaCode proxyAreaCode)
    {
        startPage();
        List<ProxyAreaCode> list = proxyAreaCodeService.selectProxyAreaCodeList(proxyAreaCode);
        return getDataTable(list);
    }

    /**
     * 导出IP代理地域列表
     */
    @RequiresPermissions("business:ProxyAreaCode:export")
    @Log(title = "IP代理地域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProxyAreaCode proxyAreaCode)
    {
        List<ProxyAreaCode> list = proxyAreaCodeService.selectProxyAreaCodeList(proxyAreaCode);
        ExcelUtil<ProxyAreaCode> util = new ExcelUtil<ProxyAreaCode>(ProxyAreaCode.class);
        return util.exportExcel(list, "IP代理地域数据");
    }

    /**
     * 新增IP代理地域
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存IP代理地域
     */
    @RequiresPermissions("business:ProxyAreaCode:add")
    @Log(title = "IP代理地域", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProxyAreaCode proxyAreaCode)
    {
        return toAjax(proxyAreaCodeService.insertProxyAreaCode(proxyAreaCode));
    }

    /**
     * 修改IP代理地域
     */
    @RequiresPermissions("business:ProxyAreaCode:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProxyAreaCode proxyAreaCode = proxyAreaCodeService.selectProxyAreaCodeById(id);
        mmap.put("proxyAreaCode", proxyAreaCode);
        return prefix + "/edit";
    }

    /**
     * 修改保存IP代理地域
     */
    @RequiresPermissions("business:ProxyAreaCode:edit")
    @Log(title = "IP代理地域", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProxyAreaCode proxyAreaCode)
    {
        return toAjax(proxyAreaCodeService.updateProxyAreaCode(proxyAreaCode));
    }

    @PostMapping("/getCityByCode/{code}")
    @ResponseBody
    public AjaxResult getCityByCode(@PathVariable("code") String code)
    {
        List<ProxyAreaCode> proxyAreaCodeList =  proxyAreaCodeService.selectCityCodeList(code);
        return AjaxResult.success(proxyAreaCodeList);
    }

    /**
     * 删除IP代理地域
     */
    @RequiresPermissions("business:ProxyAreaCode:remove")
    @Log(title = "IP代理地域", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(proxyAreaCodeService.deleteProxyAreaCodeByIds(ids));
    }
}
